<template>
  <div class="header-search">
    <div class="search clearfix">
      <div class="search-title">
        <a href="#">
          <img
            src="//s0.meituan.net/bs/fe-web-meituan/10afbf1/img/logo.png"
            alt="美团"
          />
        </a>
      </div>
      <div class="search-inp-module">
        <form class="search-inp">
          <input
            type="text"
            placeholder="请输入商家名称或地址"
            class="inp"
            @focus="fous"
            @blur="blur"
            v-model="inpData"
            ref="inp"
          />
          <el-button
            type="primary"
            icon="el-icon-search"
            class="btn"
            @click="handleClick"
          ></el-button>
          <div class="search-history" v-if="searchHistory">
            <div class="his-title">
              <h6>最近搜索</h6>
              <span class="clear-history" @click="delClick">删除搜索历史</span>
            </div>
            <ul>
              <li v-for="(item, i) in searchData" :key="i">{{ item }}</li>
            </ul>
          </div>
        </form>
        <!--  -->

        <div class="search-session">
          <ul>
            <li></li>
          </ul>
        </div>
        <div class="mess">
          <a href="">度假村</a><a href="">民宿</a><a href="">酒店</a>
          <a href="">度假村</a><a href="">民宿</a><a href="">酒店</a>
          <a href="">度假村</a><a href="">民宿</a><a href="">酒店</a>
          <a href="">度假村</a><a href="">民宿</a><a href="">酒店</a>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      inpData: "",
      searchData: [],
      searchHistory: false,
    };
  },
  methods: {
    fous() {
      if (!this.inpData) {
        this.searchHistory = true;
      } else {
        this.searchHistory = false;
      }
    },
    blur() {
      setTimeout(() => {
        this.searchHistory = false;
      }, 200);
    },
    handleClick() {
      if (this.$refs.inp.value == "") {
        return;
      } else {
        this.searchData.push(this.$refs.inp.value);
      }
    },
    delClick() {
      this.searchData = [];
    },
  },
  watch: {
    inpData(newValue, oldValue) {
      this.fous();
    },
  },
};
</script>

<style lang="less" scoped>
.header-search {
  background-color: #fff;
  width: 100%;
  .search {
    width: 1190px;
    margin: 0 auto;
    padding-bottom: 35px;
    position: relative;
    .search-title {
      float: left;
      padding: 28px 60px 40px 0px;
      img {
        width: 126px;
        height: 46px;
        object-fit: cover;
      }
    }
    .search-inp-module {
      position: absolute;
      left: 50%;
      transform: translateX(-50%);
      padding-top: 28px;
      .search-inp {
        width: 550px;
        height: 40px;
        background: #fff;
        display: flex;
        box-sizing: border-box;
        position: relative;
        .inp {
          width: 85%;
          height: 100%;
          line-height: 100%;
          border: 1px solid #e5e5e5;
          border-right: none;
          border-radius: 4px 0 0 4px;
          box-sizing: border-box;
          display: inline-block !important;
          padding: 15px;
          font-size: 14px;
          background: transparent;
        }
        .btn {
          width: 15%;
          border-radius: 0px 4px 4px 0px;
          border-color: #ffc300;
          line-height: 100%;
          height: 100%;
          box-sizing: border-box;
          background: #ffc300;
          color: #222222;
          font-size: 18px;
          font-weight: bold;
          cursor: pointer;
          border-bottom-right-radius: 4px;
          border-top-right-radius: 4px;
        }
        .search-history {
          width: 85%;
          border: 1px solid #e5e5e5;
          border-top: none;
          background: #fff;
          padding: 10px;
          box-sizing: border-box;
          position: absolute;
          top: 40px;
          left: 0;
          z-index: 99;
          color: #999;
          font-size: 12px;
          text-align: left;
          .his-title {
            display: flex;
            justify-content: space-between;
            margin-bottom: 10px;
            .clear-history {
              cursor: pointer;
            }
          }
          ul {
            padding: 0px 5px 10px 5px;
            li {
              margin-right: 10px;
              display: inline-block;
              color: #999;
            }
          }
        }
      }

      .mess {
        padding: 10px;
        a {
          margin-right: 15px;
          &:hover {
            color: #ffc300;
          }
        }
      }
    }
  }
}
</style>